$(document).ready(function(){ 
	$("#btn_size").click(function(){
		$("#layer92").slideToggle();
	});
	$("#closed_code").click(function(){
		$("#layer304").slideToggle();
	});
	
	//关隐藏层
	$(".closed_code").each(function(i){
		$('.closed_code').bind('click', function() {
			 $(this).closest('div').hide();
		});
	});
	$("#classInner").append($("#classlists a:eq(2)").clone());
	$("#classInner").append('  ');
	$("#classInner").append($("#classlists a:eq(3)").clone());

	//ajax分页
	Ajaxpage.loadpage();
	var options = { 
            dataType: 'json',
            success:  showResponse
    };
    $('#mumayiform').ajaxForm(options); 
	$('#replaymumayiform').ajaxForm(options); 
	var bugoptions = { 
            dataType: 'json',
            success:  sResponse
    };

    $('#mumayibugform').ajaxForm(bugoptions);
	$(".center_zj_left .hd_tab a").each(function(i){
		$(this).click(function(){
			$(".center_zj_left .hd_tab a").removeClass().eq(i).addClass("now");
			$(".center_zj_left .appinfo_box").hide().eq(i).show();
		});
	});

	$('#refreshcaptha').click(function(){
		$('#validateimg').attr('src',"/include/vdimgck.php?"+Math.random());
	});
	$(".stars a").each(function(i,n){
		
		var cookieoldtext = $.cookie(COOKIE_RRE+'oldtext'+SOFT_ID);
		if(cookieoldtext){
			$('#showtext').text(cookieoldtext);
			$('#oldtext').text(cookieoldtext);
		}
		var cookieoldscore = $.cookie(COOKIE_RRE+'oldscore'+SOFT_ID);
		if(cookieoldscore){
			$('#oldscore').text(cookieoldscore);
			this.className="rank_now" +cookieoldscore;
		}

		var peoplenum;
		var cookiepeoplenum = $.cookie(COOKIE_RRE+'peoplenum'+SOFT_ID);
		if(cookiepeoplenum){
			peoplenum=cookiepeoplenum;
		}else{
			peoplenum=$('#peoplenum').text();
		}
		$('#speople').text('已有'+peoplenum+'人评分');
		
	});


	 $(".stars a").each(function(i,n){
			var timeout,$this = $(n);
			//$.cookie(COOKIE_RRE+SOFT_ID, null);
			var cookie = $.cookie(COOKIE_RRE+SOFT_ID) || COOKIE_RRE;
			var hasdone = (cookie.indexOf(SOFT_ID) != -1); //是否含有id
			$this.mousemove(function(event) {
				if (timeout) {
					clearTimeout(timeout);
				}
			    var point = parseInt((event.pageX - $(this).offset().left)/12) * 5;
				if(point<=10){$('.c_f60').text('不给力');}
				if(point>10&&point<=20){$('.c_f60').text('一般般');}
				if(point>20&&point<=30){$('.c_f60').text('一般');}
				if(point>30&&point<=40){$('.c_f60').text('还不错');}
				if(point>40&&point<=50){$('.c_f60').text('强烈推荐');}
				
				var peoplenum;
				var cookiepeoplenum = $.cookie(COOKIE_RRE+'peoplenum'+SOFT_ID);
				if(cookiepeoplenum){
					peoplenum=cookiepeoplenum;
				}else{
					peoplenum=$('#peoplenum').text();
				}
				$('#speople').text('已有'+peoplenum+'人评分');
				$('#myscore').text('我的评分：');
				if(point>50)point=50;
	            this.className="rank_now" + point;
				
			});

			$this.mouseout(function(n) {
				var points;
				var cookieoldscore = $.cookie(COOKIE_RRE+'oldscore'+SOFT_ID);
				var cookieoldtext = $.cookie(COOKIE_RRE+'oldtext'+SOFT_ID);
				if(cookieoldscore){
					points=cookieoldscore;
				}else{
					points=$("#oldscore").text();
				}
				this.className ="rank_now"+points;
				
				//$('#speople').text('鼠标移动评分');
				var peoplenum;
				var cookiepeoplenum = $.cookie(COOKIE_RRE+'peoplenum'+SOFT_ID);
				if(cookiepeoplenum){
					peoplenum=cookiepeoplenum;
				}else{
					peoplenum=$('#peoplenum').text();
				}
				$('#speople').text('已有'+peoplenum+'人评分');
				$('#myscore').text('推荐指数：');
				if(cookieoldtext){
					$('#showtext').text(cookieoldtext);
				}else{
					$('#showtext').text($("#oldtext").text());
				}
				
			});
			window.setRankStar = function(num) {
				if (hasdone) {
					return false;
				}
				$this.hide();
				$this.fadeIn(600);
			
				var star=num;
				$.ajax({
					type:"POST",
					url:"/plus/score.php",
					data:{
						star: star,
						aid:SOFT_ID
					},
					dataType:'json',
					success:function(datas){
						
						$this[0].className = "rank_now"+datas.score;
						$.cookie(COOKIE_RRE+'peoplenum'+SOFT_ID,datas.scorenum);
						$.cookie(COOKIE_RRE+'oldscore'+SOFT_ID,datas.score);

						var point=datas.score;
						var oldtext;

						if(point<=10){oldtext='不给力';}
						if(point>10&&point<=20){oldtext='一般般';}
						if(point>20&&point<=30){oldtext='一般';}
						if(point>30&&point<=40){oldtext='还不错';}
						if(point>40&&point<=50){oldtext='强烈推荐';}
						$('.c_f60').text(oldtext);
						$.cookie(COOKIE_RRE+'oldtext'+SOFT_ID,oldtext);
						
						var peoplenum;
						$('#peoplenum').text(datas.scorenum);
						if(datas.scorenum){
							peoplenum=datas.scorenum;
						}else{
							peoplenum=$('#peoplenum').text();
						}
						if(peoplenum==0){
							$('#speople').text('已有10人评分');
						}else{
							$('#speople').text('已有'+peoplenum+'人评分');
						}
						
						$('#speople').text('鼠标移动评分');
						$('#myscore').text('推荐指数：');
						if(oldtext){
							$('#showtext').text(oldtext);
						}else{
							$('#showtext').text($("#oldtext").text());
						}
					}
				});
				hasdone = true;
				cookieval= cookie + "~" + SOFT_ID;
				$.cookie(COOKIE_RRE+SOFT_ID, cookieval);
				
				return true;
			};
			$this.click(function(n) {
				this.blur();
				var result=setRankStar(this.className.match(/\d+/)[0]);
				if(result){
					$(this).mumayitips({messages:'感谢您的支持,评分成功!'}); 
				}else{
					$(this).mumayitips({ messages:'您已经评过分了!',type:2});
				}
				
				return false;
			});
	  });  
	
});

function Showpermission(){
	$(".center_zj_left .appinfo_box").hide();
	$(".center_zj_left .hd_tab a").removeClass();
	$('#permissioncontent').show();
	$("#permissionshow").addClass("now");
}

function ShowVersionLog(obj,num){
	var name=$(obj).text();
	if(name=='查看'){
		$(obj).text('隐藏');
	}else{
		$(obj).text('查看');
	}
	$('.showlog'+num).toggle();
}

$('.fr').live('click', function() {
	var commentid=$(this).attr("id");
	CommentString=commentid.split("_");
	IdCode=parseInt(CommentString[1]); 
	$('#comment_form').insertAfter($('.commentfrom_'+IdCode)).show();
	$('#reply_id').val(IdCode);
	$('#replay_validate').val('');
	$('#replay_msg').val(' ');
	var options = { 
            dataType: 'json',
            success:  showResponse
    };
	$('#replaymumayiform').ajaxForm(options); 
});

$('#soncaptha').live('click', function() {
		$('#sonvalidateimg').attr('src',"/include/vdimgck.php?"+Math.random());
});

function docsurl_getbyid(id) {
		itm = null;
		if (document.getElementById) {
			itm = document.getElementById(id);
		} else if (document.all)	{
			itm = document.all[id];
		} else if (document.layers) {
			itm = document.layers[id];
		}
		return itm;
}

function copydocurl(obj){
	 var rng = document.body.createTextRange();
	 rng.moveToElementText(obj);
	 rng.scrollIntoView();
	 rng.select();
	 rng.execCommand("Copy");
	 rng.collapse(false);
	 alert('该软件信息已复制，到论坛直接粘贴即可。');
}


function sResponse(responseText)  { 
	
	if(responseText.status){
		$("#listmessage").mumayitips({ messages:responseText.message});
		$("#listmessage").html();
		$("#bugcontents").attr("value","");
		hideSubmit();
		setTimeout(function(){
			$.facebox.close();
		}, 1000 );
	}else{
		$("#listmessage").html(responseText.message);
	}
}

function showSubmit(){
	$("#bugcontent").show();	
}

function hideSubmit(){
	$("#bugcontent").hide();
}

function showResponse(responseText)  { 
	if(responseText.status){
		 $("#msgval").mumayitips({messages:responseText.message,type:1,times:1500});
		 $("form")[0].reset();
		 $("#validateval").val('');
		 $("#msgval").val('');
		 Ajaxpage.loadpage();
	}else{
		$("#msgval").mumayitips({messages:responseText.message,type:3,times:1500});
	}
}